package com.itheima.interceptor;

import com.itheima.domain.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


public class ResourceInterceptor implements HandlerInterceptor {
    private List<String> ignoreUrl;

    public ResourceInterceptor(List<String> ignoreUrl) {
        this.ignoreUrl = ignoreUrl;
    }

    public void setIgnoreUrl(List<String> ignoreUrl) {
        this.ignoreUrl = ignoreUrl;
    }
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User user = (User)request.getSession().getAttribute("USER_SESSION");
        String url = request.getRequestURI();
        if(url!=null){
            return true;
        }
        if(url.indexOf("login")>=0){
            return true;
        }
        request.setAttribute("msg","你还没有登录，请先登录！");
        request.getRequestDispatcher("admin/login.jsp").forward(request,response);
        return false;
    }
}
